/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.view.renderer
{
	import flash.events.MouseEvent;
	
	import multimedia.control.event.feed.UpdateFeedItemStatusEvent;
	import multimedia.model.vo.FeedItemVO;
	import multimedia.model.vo.FeedVO;

	public class UpdateFeedItemStatusButton extends ImageBorder
	{
		private var feedItem:FeedItemVO;
		
		public function UpdateFeedItemStatusButton()
		{
			super();
			
			this.height = 16;
			this.width = 16;
			this.addEventListener(MouseEvent.CLICK, updateFeedItemStatus);
		}

		// getter for node data
		[Bindable]
		public function get node():FeedItemVO
		{
			return feedItem;
		}

		// setter for node data
		public function set node(value:FeedItemVO):void
		{
			this.feedItem = value;
			
			this.source = feedItem.status == FeedItemVO.INCLUDE ? 'multimedia/assets/feed--minus.png' : 'multimedia/assets/feed--plus.png';
			this.toolTip = feedItem.status == FeedItemVO.INCLUDE ? "FeedItem vom Newsticker ausschließen" : "FeedItem zum Newsticker hinzufügen";
		}
		
		private function updateFeedItemStatus(event:MouseEvent):void
		{
			feedItem.status = feedItem.status == FeedItemVO.INCLUDE ? FeedItemVO.EXCLUDE : FeedItemVO.INCLUDE;
			var feed:FeedVO = new FeedVO();
			feed.feed_id = feedItem.feed_id;
			new UpdateFeedItemStatusEvent(feedItem, feed).dispatch();
		}

	}
}